//
//  main.cpp
//  testpcap
//
//  Created by bugforever on 1/10/15.
//  Copyright (c) 2015 bugforever. All rights reserved.
//

#include "stdio.h"
#include <iostream>
#include "time.h"

#include "../../Include/network_struct.h"
#include "../../Common/device_retriever/device_retriever.h"
#include "network_filter_test_ethernet.h"
#include "../../Common/network_filter/network_filter_ipv4.h"

int main(int argc, const char * argv[])
{
    device_retriever retriever;
    std::vector<device_info *> * ptr_info = 0;
    
    bool ret = retriever.get_device_list( &ptr_info );
    
    if( !ret )
        return 0;
    
    std::vector<device_info *>::iterator iter = ptr_info->begin();
    std::vector<device_info *>::iterator itere = ptr_info->end();
    
    int index = 0;
    
    while( iter != itere )
    {
		std::cout << index << ". Name: " << (*iter)->get_name();

		if ((*iter)->get_friendlyname())
			std::cout << " (" << (*iter)->get_friendlyname() << ")\t";

		if ((*iter)->get_description())
			std::cout << (*iter)->get_description();
        
        std::cout<<std::endl;
        
        index++;
        iter++;
    }
    
    std::cout<<"Please select the device you want to do the capture: ";
    
    std::cin>>index;
    
    iter = ptr_info->begin();
    
    iter = iter + index;
    
    pcap_engine engine;
    network_filter_ipv4 ipv4_filter;
    
    ipv4_filter.set_parent_network_filter( &engine );
    engine.set_network_filter( &ipv4_filter );
    
    engine.start_engine( *iter );
    
    std::cin>>index;
    
    engine.stop_engine();
    
    return 0;
}
